package com.zx.mes.hyl.security.core.authentication;

import com.zx.mes.hyl.security.core.validate.code.ValidateCodeProcessorManager;
import com.zx.mes.hyl.security.core.validate.code.ValidateCodeRepository;
import com.zx.mes.hyl.security.core.validate.code.sms.impl.DefaultValidateCodeRepository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 认证相关的扩展点配置,配置在这里的bean,业务系统都可以通过声明同类型或同名的bean来覆盖
 * 模块默认的配置
 * @author huayunlong
 * @date 2018-6-2
 */
@Configuration
public class AuthenticationBeanConfig {


    /**
     * 默认的密码处理器
     * @return BCryptPasswordEncoder
     */
    @Bean
    @ConditionalOnMissingBean(PasswordEncoder.class)
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    /**
     * 默认认证器
     * @return UserDetailsService
     */
    @Bean
    @ConditionalOnMissingBean(UserDetailsService.class)
    public UserDetailsService userDetailsService() {
        return new DefaultUserDetailsService();
    }


    /**
     * 默认 校验码存取
     * @return DefaultValidateCodeRepository
     */
    @Bean
    @ConditionalOnMissingBean(ValidateCodeRepository.class)
    public ValidateCodeRepository validateCodeRepository(){
        return new DefaultValidateCodeRepository();
    }

    @Bean
    public ValidateCodeProcessorManager validateCodeProcessorManager(){
        return new ValidateCodeProcessorManager();
    }
}
